package net.cctms.zhishu.webAppFramework.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import net.cctms.zhishu.R;


/**
 * 启动activity
 * Created by yanfei on 2017/8/9.
 */
public class IntentUtil {
    /**
     * 底部进入
     * @param context
     * @param intent
     */
    public static void startActivityFromBottom(Context context,Intent intent) {
        ((Activity)context).startActivity(intent);
        ((Activity)context).overridePendingTransition(R.anim.push_bottom_in, R.anim.activity_notmove);
    }

    /**
     * 页面跳转动画，从右进
     * @param activity
     */
    public static void startActivity(Activity activity,Intent intent){
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.push_right_in, R.anim.activity_notmove);
    }

    /**
     *
     * @param activity
     */
    public static void startActivity(Activity activity,Intent intent , int animIn , int animOut){
        activity.startActivity(intent);
        activity.overridePendingTransition(animIn, animOut);
    }

    /**
     * 启动Activity
     *
     * @param activity
     * @param intent
     * @param requestCode
     */
    public static void startActivityForResult(Activity activity,Intent intent,int requestCode){
        activity.startActivityForResult(intent, requestCode);
        //activity.overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
        activity.overridePendingTransition(R.anim.push_right_in, R.anim.activity_notmove);
    }


    /**
     * 启动Activity ，不带参数
     * @param activity
     * @param cls
     */
    public static void startActivity(Activity activity,Class<?> cls){
        Intent intent=new Intent();
        intent.setClass(activity,cls);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.push_right_in, R.anim.activity_notmove);
    }

    /**
     * 启动Activity
     * @param activity
     * @param cls
     */
    public static void startActivityForResult(Activity activity,Class<?> cls , int requestCode){
        Intent intent=new Intent();
        intent.setClass(activity, cls);
        activity.startActivityForResult(intent, requestCode);
        activity.overridePendingTransition(R.anim.push_right_in, R.anim.activity_notmove);
    }
    /**
     * 启动Activity ，带参数
     * @param activity
     * @param cls
     * @param bundle
     */
    public static void startActivity(Activity activity,Class<?> cls,Bundle bundle){
        Intent intent=new Intent();
        intent.setClass(activity,cls);
        intent.putExtras(bundle);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.push_right_in, R.anim.activity_notmove);
    }

    /**
     * 启动Activity ，带参数无动画
     * @param activity
     * @param cls
     * @param bundle
     */
    public static void startActivityNoAnim(Activity activity,Class<?> cls,Bundle bundle){
        Intent intent=new Intent();
        intent.setClass(activity,cls);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }

    /**
     * 启动Activity ，无动画
     * @param activity
     * @param cls
     */
    public static void startActivityNoAnim(Activity activity,Class<?> cls){
        Intent intent=new Intent();
        intent.setClass(activity, cls);
        activity.startActivity(intent);
    }

    /**
     * 判断Action对应的Activity是否存在系统中
     * @param context
     * @param action
     * @return
     */
    public static boolean existAction(Context context, String action){
        Intent intent = new Intent();
        intent.setAction(action);
        if(context.getPackageManager().resolveActivity(intent, 0) != null) {
            return true;
        }
        return false;
    }

    /**
     * 启动Activity ，不带参数
     * @param activity
     * @param action
     */
    public static void startActivityByAction(Activity activity , String action , Bundle bundle){
        Intent intent = new Intent(action);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.putExtras(bundle);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.push_right_in, R.anim.activity_notmove);
    }

    /**
     * 启动Activity ，不带参数
     * @param activity
     * @param url
     */
    public static void startSystemBrowser(Activity activity , String url){
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        Uri content_url = Uri.parse(url);
        intent.setData(content_url);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.push_right_in, R.anim.activity_notmove);
    }
}
